<html>
	<head>
		<style type="text/css">
			#div_content
			{
				float: top;
				margin: 10px 150px 10px 150px;
				padding: 0px;
				display:block;
				border: 0px solid;
				font-size: 13px;
				font-family: verdana, helvetica, arial, sans-serif;
			}
			
			table
			{
				font-size: 13px;
				font-family: verdana, helvetica, arial, sans-serif;
				width: 100%;
				cellspacing: 0px;
				cellpadding: 0px;	
				padding:3px;

				background-color:#ffffff;
				border:1px solid #c3c3c3;
				border-collapse:collapse;				
			}

			table thead
			{
				text-align: center;
				font-weight: bold;				
				background-color: #e5eecc;
				border: 1px solid #c3c3c3;
				vertical-align: middle;				
			}

			table thead td
			{
				border: 1px solid #c3c3c3;
				padding: 3px;
				vertical-align: middle;
			}

			table tfoot
			{
				text-align: center;
				font-weight: bold;				
				background-color: #e5eecc;
				border: 1px solid #c3c3c3;
				vertical-align: middle;				
			}
			
			table tr
			{
				width: 100%;
			}

			table td 
			{
				border: 1px dotted #c3c3c3;
				padding: 3px;
				vertical-align: middle;
			}
						
			#table_payslip_header
			{
			}

			#table_attendance
			{
				font-size: 13px;
				font-family: verdana, helvetica, arial, sans-serif;
				border: 1px solid;
				width: 100%;
				cellspacing: 0px;
				cellpadding: 0px;				
			}

			#table_attendance
			{
				border: 1px solid;
			}
			
			.date
			{
				text-align: center;
			}
			
			.number
			{
				text-align: right;
				width: 20%;
			}
			
			.input_number
			{
				text-align: right;
				padding-right: 5px;
				padding-left: 5px;
			}
		</style>		
	</head>
	<body>
		<div id="div_content">
<?php
	//Employee id
	$employee_id = "";
	if(isset($_GET['emp_id']))		
		$employee_id = $_GET['emp_id'];

	//Payroll date
	$factor = 0;
	if(isset($_GET['factor']))		
		$factor = $_GET['factor'];
		
	$payroll_year = "";
	if(isset($_GET['year']))		
		$payroll_year = $_GET['year'];
	else
		$payroll_year = date("Y");	
		
	$payroll_month = "";	
	if(isset($_GET['month']))		
		$payroll_month = $_GET['month'];
	else
		$payroll_month = date("n");	

	$payroll_start_day = 1;
	$payroll_date = $payroll_year . "-" . $payroll_month . "-" . $payroll_start_day;
	$payroll_date = strtotime($factor . " month", strtotime($payroll_date));
	
	$payroll_year = date("Y", $payroll_date);
	$payroll_month = date("n", $payroll_date);	
	$payroll_end_day = date("t", $payroll_date);	
			
	$late_duration = 10;
	
	$mysql_connect = mysql_connect('localhost', 'hr_mysql', 'hr_mysql');

	if ($mysql_connect)
	{				
		mysql_select_db('hr_mysql', $mysql_connect);

		if(empty($employee_id))
		{		
			$mysql_query = "select * from hs_hr_employee";		
			$mysql_result = mysql_query($mysql_query);
			if(!$mysql_result)		
				exit;
			
			$employee_list = array();
			while($mysql_row = mysql_fetch_array($mysql_result))
				$employee_list[] = $mysql_row;
?>
			<div style="text-align:center; border:1px solid;font-weight:bold;padding:5px;">
				Payroll of <?php echo strftime("%B", $payroll_date) . ", " . $payroll_year; ?>
				<br/>Employee list
			</div>
			<div stlyle="clear:both;">
				&nbsp;
			</div>		
			<div>
				<table id="table_header">
					<thead>
						<tr>
							<td>No</td>
							<td>Id</td>
							<td>Name</td>
							<td>Gender</td>
							<td style="width:110px;">
								<a href="./payslip.php?factor=<?php echo $factor - 1; ?>"><<</a> | <a href="./payslip.php">Now</a> | <a href="./payslip.php?factor=<?php echo $factor + 1; ?>">>></a>
							</td>
						</tr>
					</thead>
					<tbody>	
<?php
			$counter = 0;
			foreach($employee_list as &$mysql_row)
			{
				$counter += 1;
?>
						<tr>
							<td><?php echo $counter; ?></td>
							<td style="text-align:center;"><?php echo $mysql_row['employee_id'];?></td>
							<td><?php echo $mysql_row['emp_lastname'] ." ".$mysql_row['emp_firstname'];?></td>
							<td><?php echo $mysql_row['emp_gender'];?></td>
							<td style="text-align:center;">
								<a href="./payslip.php?emp_id=<?php echo $mysql_row['emp_number'];?>&factor=<?php echo $factor;?>">Print</a>
							</td>
						</tr>
<?php
			}
?>					
					</tbody>			
				</table>
			</div>		

<?php			
			exit;
		}
	
		//Employee
		$mysql_query = "select a.*, b.sal_grd_code, IFNULL(b.ebsal_basic_salary, 0) as ebsal_basic_salary from hs_hr_employee a left join hs_hr_emp_basicsalary b on a.emp_number = b.emp_number where a.emp_number = '$employee_id'";		
		$mysql_result = mysql_query($mysql_query);
		if(!$mysql_result)		
			exit;
		$employee_info = mysql_fetch_array($mysql_result);
		$basic_salary = $employee_info['ebsal_basic_salary'];
		$unit_salary = $basic_salary / 30;
		
		//Holidays
		$mysql_query = "select ifnull(sum(length), 0) as length from hs_hr_holidays where year(date) = '$payroll_year' and month(date) = '$payroll_month'";
		$mysql_result = mysql_query($mysql_query);
		if(!$mysql_result)		
			exit;		
		$holidays_info = mysql_fetch_array($mysql_result);		
		$holidays = $holidays_info[0] / 8;
		
		//Leave
		$mysql_query = "select ifnull(sum(leave_length_days), 0) as leave_length_days from hs_hr_leave where leave_status != 0 and employee_id = '$employee_id' and year(leave_date) = '$payroll_year' and month(leave_date) = '$payroll_month' group by employee_id";

		$mysql_result = mysql_query($mysql_query);
		if(!$mysql_result)		
			exit;		
		$leave_info = mysql_fetch_array($mysql_result);		
		$leave = $leave_info[0];
		//echo $mysql_query;
		//late
		/*
		$mysql_query = "SELECT COUNT(*) AS late	FROM hs_hr_attendance WHERE employee_id = '$employee_id' AND YEAR(punchin_time) = '$payroll_year' AND MONTH(punchin_time) = '$payroll_month' AND TIMESTAMPDIFF(MINUTE, punchin_time, STR_TO_DATE(CONCAT(DAY(punchin_time), ', ', MONTH(punchin_time), ', ', YEAR(punchin_time), ' 07:10:00'), '%d,%m,%Y %h:%i:%s')) < 0";
		*/
		$mysql_query = "SELECT COUNT(*) AS late	FROM hs_hr_attendance a INNER JOIN hs_hr_employee b ON a.`employee_id` = b.`employee_id` INNER JOIN hs_hr_employee_workshift c ON b.`emp_number` = c.`emp_number` INNER JOIN hs_hr_workshift d ON c.`workshift_id` = d.`workshift_id` WHERE a.employee_id = '$employee_id' AND YEAR(punchin_time) = '$payroll_year' AND MONTH(punchin_time) = '$payroll_month' AND ((TIME(a.`punchin_time`) >= ADDTIME(d.`morning_in`, '00:11:00')) OR (TIME(a.`out_note`) >= ADDTIME(d.`afternoon_in`, '00:11:00')))";
		//echo $mysql_query;
		$mysql_result = mysql_query($mysql_query);
		if(!$mysql_result)		
			exit;		
		$late_info = mysql_fetch_array($mysql_result);		
		$late = (int)($late_info[0] / 3);

		//Day off
		$dayoff_ = 0 ; 
		$dayoff = 0;
		for ($counter = $payroll_start_day; $counter <= $payroll_end_day; $counter++)
		{
			$mysql_query0 = "SELECT attendance_id FROM hs_hr_attendance 
				WHERE (employee_id = '$employee_id' AND YEAR(punchout_time) = '$payroll_year' AND MONTH(punchout_time) = '$payroll_month' 
				AND DAY(punchout_time) = '$counter')OR (employee_id = '$employee_id' AND YEAR(punchin_time) = '$payroll_year' AND MONTH(punchin_time) = '$payroll_month'
				AND DAY(punchin_time) = '$counter')";	
			$mysql_result0 = mysql_query($mysql_query0);
			$absent_find = mysql_fetch_array($mysql_result0);

			if($absent_find == '')
			{
				$date_ = $payroll_year . "-" . substr("00" . $payroll_month, 2*-1) . "-" . substr("00" . $counter, 2*-1);
				$mysql_query1 = "SELECT * FROM `hs_hr_holidays` WHERE `date`='$date_'";
				$mysql_result1 = mysql_query($mysql_query1);
				$absent_find2 = mysql_fetch_array($mysql_result1);


				if($absent_find2 == '')
				{ 
					$a =  cal_to_jd(CAL_GREGORIAN,substr("00" . $payroll_month, 2*-1),substr("00" . $counter, 2*-1),$payroll_year);
					$dayofweek = jddayofweek($a,1);
					switch ($dayofweek) 
					{
						case "Monday": $dayoff_ =1;break;
						case "Tuesday": $dayoff_ =2;break;
						case "Wednesday": $dayoff_ =3;break;
						case "Thursday": $dayoff_ =4;break;
						case "Friday": $dayoff_ =5;break;
						case "Saturday": $dayoff_ =6;break;
						case "Sunday": $dayoff_ =7;break;
					}


					$mysql_query = "SELECT * FROM hs_hr_weekends WHERE length != 0";
					//echo $mysql_query;
					$mysql_result = mysql_query($mysql_query);
					if(!$mysql_result)		
						exit;		
					while($day_row = mysql_fetch_array($mysql_result))
					{
						if($day_row[0] == $dayoff_)
						{
							if($day_row[1] = 4) 
								$dayoff += 0.5;
							else 
								$dayoff += 1;
						}
					}
				}
			}
		}									
	
		//Absent
		//$mysql_query = "SELECT COUNT(DISTINCT DAY(punchin_time)) AS late FROM hs_hr_attendance WHERE employee_id = '$employee_id' AND YEAR(punchin_time) = '$payroll_year' AND MONTH(punchin_time) = '$payroll_month'";

		// new by vannarith
		$mysql_query = "SELECT COUNT(*) AS late FROM hs_hr_attendance WHERE (employee_id = '$employee_id' AND YEAR(punchout_time) = '$payroll_year' AND MONTH(punchout_time) = '$payroll_month')OR (employee_id = '$employee_id' AND YEAR(punchin_time) = '$payroll_year' AND MONTH(punchin_time) = '$payroll_month')";										
		//echo $mysql_query;
		$mysql_result = mysql_query($mysql_query);
		if(!$mysql_result)		
			exit;		
		$absent_info = mysql_fetch_array($mysql_result);

		//$absent = $payroll_end_day - $absent_info[0] - $leave;


		//by vannarith
		$absent = $payroll_end_day - $absent_info[0] - $leave - $holidays - $dayoff +0;
		if($absent < 0.00) $absent = 0; 		
		//echo $dayoff ." dayoff<br>".$absent." absent<br>".$payroll_end_day ." payroll_end_day<br>". $absent_info[0] ." absent_info[0]<br>".
		//$leave ." leave<br>". $holidays . " holidays";

		//Debt
		$mysql_query = "SELECT SUM(amount) as DebtAmount FROM hs_hr_loan WHERE employee_id = '$employee_id'";
		$mysql_result = mysql_query($mysql_query);
		if(!$mysql_result)
			exit;
		
		$mysql_row = mysql_fetch_row($mysql_result);
		$total_debt_amount = $mysql_row[0];		
		
		$mysql_query = "SELECT SUM(payroll_amount) as ReimburseAmount FROM hs_hr_emp_payroll_detail WHERE employee_id = '$employee_id' AND payroll_parameter_id = '6'";
		$mysql_result = mysql_query($mysql_query);
		if(!$mysql_result)
			exit;

		$mysql_row = mysql_fetch_row($mysql_result);
		$total_reimburse_amount = $mysql_row[0];
		
		//Remaining debt amount
		$total_debt_amount -= $total_reimburse_amount;
			
		//Debt, Saving, Lunch, Petrol, Bonus
		$mysql_query = "SELECT * FROM hs_hr_emp_payroll_detail WHERE employee_id = '$employee_id' AND YEAR(payroll_date) = '$payroll_year' AND MONTH(payroll_date) = '$payroll_month'";
		$mysql_result = mysql_query($mysql_query);
		if(!$mysql_result)
			exit;
		
		$payroll_list = array();
		while($mysql_row = mysql_fetch_array($mysql_result))
			$payroll_list[] = $mysql_row;
		
		$debt = 0;
		$saving = 0;
		$lunch = 0;
		$petrol = 0;
		$bonus = 0;
		foreach($payroll_list as &$mysql_row)
		{
			$payroll_parameter_id = $mysql_row["payroll_parameter_id"];			
			switch ($payroll_parameter_id) 
			{
				case 6:
					$debt = $mysql_row["payroll_amount"];
					break;
				case 7:
					$saving = $mysql_row["payroll_amount"];
					break;
				case 8:
					$lunch = $mysql_row["payroll_amount"];
					break;
				case 9:
					$petrol = $mysql_row["payroll_amount"];
					break;
				case 10:
					$bonus = $mysql_row["payroll_amount"];
					break;
			}		
		}

		//$total_salary = $basic_salary + (($holidays - $leave - $late - ($absent * 3)) * $unit_salary) - $debt - $saving + $lunch + $petrol + $bonus;

		// new by vannarith
		$total_salary = ($basic_salary + $petrol + $bonus)- ((($absent * 3) * $unit_salary) + ($late*$unit_salary) + ($leave * $unit_salary) + ($debt + $saving + $lunch));
?>
			<div style="text-align:center; border:1px solid;font-weight:bold;padding:5px;">
				Payroll of <?php echo strftime("%B", $payroll_date) . ", " . $payroll_year; ?>
			</div>
			<div stlyle="clear:both;">
				&nbsp;
			</div>		
			<div>
				<form id="frm_payslip" method="post" action="payslip_handler.php">
					<input type="hidden" name="txt_employee_id" id="txt_employee_id" value="<?php echo $employee_id; ?>" />
					<input type="hidden" name="txt_wage" id="txt_wage" value="<?php echo $unit_salary; ?>" />
					<input type="hidden" name="txt_payroll_month" id="txt_payroll_month" value="<?php echo $payroll_month; ?>" />
					<input type="hidden" name="txt_payroll_year" id="txt_payroll_year" value="<?php echo $payroll_year; ?>" />
					<input type="hidden" name="txt_factor" id="txt_factor" value="<?php echo $factor; ?>" />
					<table id="table_payslip_header">
						<thead>
							<tr>
								<td style="text-align:left;" colspan="4">
									Employee: <?php echo $employee_info['emp_lastname'] ." ". $employee_info['emp_firstname']; ?> | <a href="./payslip.php?factor=<?php echo $factor;?>">List</a>
								</td>
								<td>
									<a href="./payslip.php?emp_id=<?php echo $employee_id; ?>&factor=<?php echo $factor - 1; ?>"><<</a> | <a href="./payslip.php?emp_id=<?php echo $employee_id; ?>">Now</a> | <a href="./payslip.php?emp_id=<?php echo $employee_id; ?>&factor=<?php echo $factor + 1; ?>">>></a>
								</td>
							</tr>
						</thead>
						<tbody>					
							<tr style="text-align:center;">
								<td>Basic salary ($)</td>						  
								<td>Holidays</td>						  
								<td>Late</td>
								<td>Leave</td>
								<td>Absent</td>							
							</tr>
							<tr>
								<td style="text-align:center;"><input class="input_number" type="text" readonly name="txt_basic_salary" id="txt_basic_salary" value="<?php echo number_format($basic_salary, 2); ?>"/></td>
								<td style="text-align:center;">
									<input style="width: 38%;" class="input_number" type="text" readonly name="txt_holidays" id="txt_holidays" value="<?php echo $holidays; ?>"/>

									<input style="width: 38%;" class="input_number" type="text" readonly name="txt_holidays_amount" id="txt_holidays_amount" value="<?php
									   //echo number_format($holidays * $unit_salary, 2);
									   echo "0.00";
									 ?>"/>

								</td>
								<td style="text-align:center;">
									<input style="width: 38%;" class="input_number" type="text" readonly name="txt_late" id="txt_late" value="<?php echo $late; ?>"/>
									<input style="width: 38%;" class="input_number" type="text" readonly name="txt_late_amount" id="txt_late_amount" value="<?php echo number_format($late * $unit_salary, 2); ?>"/>
								</td>
								<td style="text-align:center;">
									<input style="width: 38%;" class="input_number" type="text" readonly name="txt_leave" id="txt_leave" value="<?php echo number_format($leave, 2); ?>"/>
									<input style="width: 38%;" class="input_number" type="text" readonly name="txt_leave_amount" id="txt_leave_amount" value="<?php echo number_format($leave * $unit_salary, 2); ?>"/>
								</td>
								<td style="text-align:center;">
									<input style="width: 38%;" class="input_number" type="text" readonly name="txt_absent" id="txt_absent" value="<?php echo $absent; ?>"/>
									<input style="width: 38%;" class="input_number" type="text" readonly name="txt_absent_amount" id="txt_absent_amount" value="<?php echo number_format(($absent*3) * $unit_salary, 2); ?>"/>
								</td>
							</tr>
							<tr style="text-align:center;">
								<td>Debt&nbsp;<strong>(<?php echo number_format($total_debt_amount, 2); ?>)</strong></td>						  
								<td>Saving</td>						  
								<td>Lunch</td>
								<td>Petrol</td>
								<td>Bonus</td>							
							</tr>
							<tr>
								<td style="text-align:center;"><input class="input_number" type="text" name="txt_debt" id="txt_debt" value="<?php echo number_format($debt, 2); ?>"/></td>
								<td style="text-align:center;"><input class="input_number" type="text" name="txt_saving" id="txt_saving" value="<?php echo number_format($saving, 2); ?>"/></td>
								<td style="text-align:center;"><input class="input_number" type="text" name="txt_lunch" id="txt_lunch" value="<?php echo number_format($lunch, 2); ?>"/></td>
								<td style="text-align:center;"><input class="input_number" type="text" name="txt_petrol" id="txt_petrol" value="<?php echo number_format($petrol, 2); ?>"/></td>
								<td style="text-align:center;"><input class="input_number" type="text" name="txt_bonus" id="txt_bonus" value="<?php echo number_format($bonus, 2); ?>"/></td>
							</tr>
							<tr>
								<td colspan="5" style="text-align:right;"><input type="submit" id="btn_submit" name="btn_submit" /></td>
							</tr>
						</tbody>			
						<tfoot>
							<tr>
								<td colspan="4" style="text-align:right;">Total salary:</td>
								<td class="number"><?php echo number_format($total_salary, 2); ?></td>
							</tr>
						</tfoot>
					</table>				
				</form>
			</div>		
			<div stlyle="clear:both;">
				&nbsp;
			</div>
			<div>
				<table id="table_attendance">
					<thead>
						<tr>
							<td colspan="7" style="text-align:left;">
								Attendance detail
							</td>
						</tr>
						<tr>
							<td rowspan="2">
								No.
							</td>
							<td rowspan="2">
								Date
							</td>
							<td colspan="2">
								Morning
							</td>							
							<td colspan="2">
								Afternoon
							</td>							
							<td rowspan="2">
								Status
							</td>
						</tr>
						<tr>
							<td>
								In
							</td>							
							<td>
								Out
							</td>							
							<td>
								In
							</td>							
							<td>
								Out
							</td>							
						</tr>
					</thead>
					<tbody>						
<?php					
		for ($counter = $payroll_start_day; $counter <= $payroll_end_day; $counter++)
		{
			/*$mysql_query = 
				"SELECT 
					a.`attendance_id`,
					a.`employee_id`,
					TIME(a.`punchin_time`) AS punchin_time,
					TIME(a.`punchout_time`) AS punchout_time,
					TIME(a.`in_note`) AS in_note,
					TIME(a.`out_note`) AS out_note,
					a.`timestamp_diff`,
					a.`status`,
					CASE 
						WHEN (TIME(a.`punchin_time`) >= ADDTIME(d.`morning_in`, '00:11:00')) THEN 1
						ELSE 0
					END AS late_morning,
					CASE 
						WHEN (TIME(a.`out_note`) >= ADDTIME(d.`afternoon_in`, '00:11:00')) THEN 1
						ELSE 0
					END AS late_afternoon
				FROM 
					hs_hr_attendance a
					INNER JOIN hs_hr_employee b ON a.`employee_id` = b.`employee_id`
					INNER JOIN hs_hr_employee_workshift c ON b.`emp_number` = c.`emp_number`
					INNER JOIN hs_hr_workshift d ON c.`workshift_id` = d.`workshift_id`
				WHERE 
					a.employee_id = '$employee_id' 
					and status = '1' 
					and year(punchin_time) = '$payroll_year' 
					and month(punchin_time) = '$payroll_month' 
					and day(punchin_time) = '$counter'";*/

			//new by vannarith
			$mysql_query = 
				"SELECT 
					a.`attendance_id`,
					a.`employee_id`,
					TIME(a.`punchin_time`) AS punchin_time,
					TIME(a.`punchout_time`) AS punchout_time,
					TIME(a.`in_note`) AS in_note,
					TIME(a.`out_note`) AS out_note,
					a.`timestamp_diff`,
					a.`status`,
					CASE 
						WHEN (TIME(a.`punchin_time`) >= ADDTIME(d.`morning_in`, '00:11:00')) THEN 1
						ELSE 0
					END AS late_morning,
					CASE 
						WHEN (TIME(a.`out_note`) >= ADDTIME(d.`afternoon_in`, '00:11:00')) THEN 1
						ELSE 0
					END AS late_afternoon
				FROM 
					hs_hr_attendance a
					INNER JOIN hs_hr_employee b ON a.`employee_id` = b.`employee_id`
					INNER JOIN hs_hr_employee_workshift c ON b.`emp_number` = c.`emp_number`
					INNER JOIN hs_hr_workshift d ON c.`workshift_id` = d.`workshift_id`
				WHERE 
					a.employee_id = '$employee_id'
					and status = '1'
					and (
                     (year(punchin_time) = '$payroll_year'
					 and month(punchin_time) = '$payroll_month'
					 and day(punchin_time) = '$counter')
                     or
                     (year(punchout_time) = '$payroll_year'
					 and month(punchout_time) = '$payroll_month'
					 and day(punchout_time) = '$counter')
                    )";

			
			$mysql_result = mysql_query($mysql_query);
			if(!$mysql_result)
				exit;
		
			$attendance_list = array();
			while($mysql_row = mysql_fetch_array($mysql_result)) 
				$attendance_list[] = $mysql_row;
		
			$attendance_status = "Absent";
?>
						<tr>
<?php
			if(count($attendance_list) == 0)
			{
				$leave_date = $payroll_year . "-" . substr("00" . $payroll_month, 2*-1) . "-" . substr("00" . $counter, 2*-1);
				$mysql_query = "SELECT COUNT(*) AS leaves FROM `hs_hr_leave` WHERE leave_date='$leave_date' AND employee_id='$employee_id'";
				$mysql_result = mysql_query($mysql_query);
				if(!$mysql_result)		
					exit;		
				$leave_day = mysql_fetch_array($mysql_result);
				if($leave_day[0] != 0) $attendance_status = "Leave"; 
				
				$mysql_query ="SELECT * FROM `hs_hr_holidays` WHERE `date`='$leave_date '"; 
				$mysql_result = mysql_query($mysql_query);
				if(!$mysql_result)		
					exit;		
				$holiday_day = mysql_fetch_array($mysql_result);
				if($holiday_day[0] != 0) $attendance_status = "Holiday";
?>
							<td><?php echo $counter; ?></td>
							<td class="date"><?php echo $payroll_year . "-" . substr("00" . $payroll_month, 2*-1) . "-" . substr("00" . $counter, 2*-1); ?></td>
							<td class="date">-</td>
							<td class="date">-</td>
							<td class="date">-</td>
							<td class="date">-</td>
							<td><?php echo $attendance_status; ?></td>
<?php
			}
			else
			{				
				/*
				$start_time = mktime(7, $late_duration, 0, $payroll_month, $counter, $payroll_year);
				$punchin_time = $attendance_list[0][2];
				$punchin_time = strtotime($punchin_time);
				
				if($start_time < $punchin_time)
					$attendance_status = "Late";
				else
					$attendance_status = "-";				
				*/
				
				$late_morning = $attendance_list[0][8];
				$late_afternoon = $attendance_list[0][9];
				if (($late_morning == 1) || ($late_afternoon))
					$attendance_status = "Late";
				else
					$attendance_status = "-";
?>
						<td><?php echo $counter; ?></td>
						<td class="date"><?php echo $payroll_year . "-" . substr("00" . $payroll_month, 2 * -1) . "-" . substr("00" . $counter, 2 * -1); ?></td>
						<td class="date"><?php echo $attendance_list[0][2]; ?></td>
						<td class="date"><?php echo $attendance_list[0][4]; ?></td>
						<td class="date"><?php echo $attendance_list[0][5]; ?></td>
						<td class="date"><?php echo $attendance_list[0][3]; ?></td>
						<td><?php echo $attendance_status; ?></td>
<?php				
			}
?>
						</tr>
<?php
		}
	}
	
	mysql_close($mysql_connect);	
?>						
					</tbody>
				</table>
			</div>					
		</div>
	</body>
</html>
